package com.onlyMe.config.objects
{
	import com.onlyMe.config.BaseNode;
	import com.onlyMe.config.objects.object.ObjectNode;
	import com.qb9.flashlib.utils.ArrayUtil;
	import com.qb9.flashlib.utils.ObjectUtil;

	public final class ObjectsNode extends BaseNode
	{
		private var idMap:Object = {};
		private var typeMap:Object = {};
		
		public function ObjectsNode()
		{
		}
		
		override protected function extractChild(node:XML):void
		{
			var object:ObjectNode = new ObjectNode().decode(node);
			idMap[object.id] = typeMap[object.type] = object;
		}
		
		public function getByType(type:String):ObjectNode
		{
			return typeMap[type];
		}
		
		public function getById(id:int):ObjectNode
		{
			return idMap[id];
		}
		
		public function get objects():Array
		{
			return ObjectUtil.values(idMap);
		}
	}
}